package com.wanho.java159.cb.controller;

import com.github.pagehelper.PageInfo;
import com.wanho.java159.common.result.R;
import com.wanho.java159.cb.po.MemberInformation;
import com.wanho.java159.cb.service.MemberInformationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
* MemberInformation 控制层
* @author ChaoFei.Zhang
* @date   2021-07-10
*/
@Api(tags = "管理MemberInformation")
@CrossOrigin
@RestController
@RequestMapping("/admin/memberInformation")
public class MemberInformationController {
    /**MemberInformation业务层对象 */
    @Resource
    private MemberInformationService memberInformationService;

    /**
    * 查询所有MemberInformation
    * @return 封装的:list 所有的MemberInformation数据
    */
    @ApiOperation("列表查询MemberInformation")
    @GetMapping("/list")
    public R listAll(){
        return R.ok().data("list",memberInformationService.list());
    }


    /**
    * 根据id删除MemberInformation
    * @param id MemberInformation的主键
    * @return ok 删除成功  error 删除失败
    */
    @ApiOperation(value = "根据id删除MemberInformation", notes = "逻辑删除")
    @DeleteMapping("/remove/{id}")
    public R removeById(@PathVariable("id") @ApiParam(value = "数据id", required = true, example = "100") Long id){
        boolean remove = memberInformationService.remove(id);
        if (remove){
        return R.ok().message("修改成功");
        }
        return R.error().message("修改失败");
    }

    /**
    * 新增一条MemberInformation记录
    * @param memberInformation 封装新增的MemberInformation数据
    * @return ok 新增成功  error 新增失败
    */
    @ApiOperation(value = "新增MemberInformation", notes = "新增MemberInformation")
    @PostMapping("/save")
    public R save(@ApiParam(value = "封装新增MemberInformation对象", required = true) @RequestBody MemberInformation memberInformation){
        boolean remove = memberInformationService.save(memberInformation) ;
        if (remove){
            return R.ok().message("新增成功");
        }
        return R.error().message("新增失败");
    }

    /**
    * 根据id查询一条MemberInformation记录
    * @param id MemberInformation的主键
    * @return 封装 record 存储 MemberInformation对象
    */
    @ApiOperation(value = "根据id查询MemberInformation", notes = "根据id查询MemberInformation")
    @GetMapping("/get/{id}")
    public R get(@PathVariable("id") @ApiParam(value = "数据id", required = true, example = "100") Long id){
        return R.ok().data("record",memberInformationService.get(id)) ;
    }

    /**
    * 修改一条MemberInformation记录
    * @param memberInformation 封装MemberInformation对象
    * @return ok 修改成功  error 修改失败
    */
    @ApiOperation(value = "修改MemberInformation", notes = "修改MemberInformation")
    @PutMapping("/update")
    public R update(@ApiParam(value = "封装修改MemberInformation对象", required = true) @RequestBody MemberInformation memberInformation){
        boolean remove = memberInformationService.update(memberInformation) ;
        if (remove){
            return R.ok().message("修改成功");
        }
        return R.error().message("修改失败");
    }

    /**
    * 分页条件查询MemberInformation记录
    * @param page 页码
    * @param limit 分页跨度
    * @param memberInformation 封装MemberInformation查询条件
    * @return pageModel 封装分页对象
    */
    @ApiOperation("获取MemberInformation分页列表")
    @GetMapping("/list/{page}/{limit}")
    public R listPage(
        @ApiParam(value = "当前页码", required = true)
        @PathVariable Long page,
        @ApiParam(value = "每页记录数", required = true)
        @PathVariable Long limit,
        @ApiParam(value = "查询对象", required = false)
        MemberInformation memberInformation) {
        PageInfo<MemberInformation> pageModel =  memberInformationService.listPage(page,limit, memberInformation);
        return R.ok().data("pageModel", pageModel);
    }
}